package application

import (
	"context"

	"github.com/liyaozong/mengo/common/di"
	"github.com/liyaozong/mengo/contracts/errors"
	"github.com/liyaozong/mengo/contracts/models"
)

func AddDevice(d models.Device, ctx context.Context, dic *di.Container) (id string, edgeXerr errors.MenGo) {
	// dbClient := bootstrapContainer.DBClientFrom(dic.Get)
	// lc := bootstrapContainer.LoggingClientFrom(dic.Get)

	// Check the existence of device service before device validation
	// exists, edgeXerr := dbClient.DeviceServiceNameExists(d.ServiceName)
	// if edgeXerr != nil {
	// 	return id, errors.NewCommonMenGo(errors.Kind(edgeXerr), fmt.Sprintf("device service '%s' existence check failed", d.ServiceName), edgeXerr)
	// } else if !exists {
	// 	return id, errors.NewCommonMenGo(errors.KindContractInvalid, fmt.Sprintf("device service '%s' does not exists", d.ServiceName), nil)
	// }

	// err := validateDeviceCallback(d, dic)
	// if err != nil {
	// 	return "", errors.NewCommonMenGoWrapper(err)
	// }

	// addedDevice, err := dbClient.AddDevice(d)
	// if err != nil {
	// 	return "", errors.NewCommonMenGoWrapper(err)
	// }

	// lc.Debugf(
	// 	"Device created on DB successfully. Device ID: %s",
	// 	addedDevice.Id,
	// )

	// go publishSystemEvent(common.DeviceSystemEventType, common.SystemEventActionAdd, d.ServiceName, addedDevice, ctx, dic)

	// return addedDevice.Id, nil
	return "0", nil
}
